package com.lokiy.kit.fragment

import android.os.Bundle
import android.util.Size
import android.view.View
import android.widget.Toast
import androidx.lifecycle.lifecycleScope
import com.lokiy.core.fragment.ViewBindingFragment
import com.lokiy.kit.databinding.FragmentAreaClickBinding
import com.lokiy.annotation.FragmentInfo
import com.lokiy.kit.ext.AreaClickItem
import com.lokiy.kit.ext.setOnAreaClick
import com.lokiy.kit.ext.setupToolbar
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

/**
 *
 * @author Lokiy
 * @date 2023-08-07 10:23
 */
@FragmentInfo("区域点击")
class AreaClickFragment : ViewBindingFragment<FragmentAreaClickBinding>() {

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        setupToolbar(binding.toolbar)

        lifecycleScope.launch {
            delay(1000)
            val toast = Toast.makeText(requireActivity(), "click!!!", Toast.LENGTH_SHORT)
            val scale = 0.2f
            binding.parent.setOnAreaClick(
                AreaClickItem(
                    Size((binding.parent.width * scale).toInt(), (binding.parent.height * scale).toInt()),
                    Size((binding.child.width * scale).toInt(), (binding.child.height * scale).toInt()),
                    (binding.child.left * scale).toInt(),
                    (binding.child.top * scale).toInt()
                )
            ) {
                toast.setText(if (it) "click!!!" else "no click~~~")
                toast.show()
            }
        }
    }
}